function SerializeObject(obj){
    if(obj === null){
       return "{errors:[\"The object is null\"]}";
    }
   else if (obj === undefined) {
    return  "{errors:[\"The object is undefined\"]}";
   }
    switch(obj.constructor){
        case Object:
            var str = "{";
            for(var o in obj){
                str +="\"" + o +"\"" + ":" + SerializeObject(obj[o]) +",";
            }
            if(str.substr(str.length-1) == ",")
                str = str.substr(0,str.length -1);
            return str + "}";
            break;
        case Array:           
            var str = "[";
            for(var o in obj){
                str += SerializeObject(obj[o]) +",";
            }
            if(str.substr(str.length-1) == ",")
                str = transfer(str.substr(0,str.length -1));
            return str + "]";
            break;
        case Boolean:
            return "\"" + transfer(obj.toString()) + "\"";
            break;
        case Date:
            return "\"" + transfer(obj.toString()) + "\"";
            break;
        case Function:
            break;
        case Number:
            return "\"" + transfer(obj.toString()) + "\"";
            break;
        case String:
            return "\"" + transfer(obj.toString()) + "\"";
            break;   
    }
}
function transfer(input) {
    var reg = new Array();
    reg[0] = /(['"])/img;
    reg[1] = /[\n\r]/img;

    input = input.replace(reg[0], "\$1");
    return input.replace(reg[1], "");
}
